package net.gateway.piggy.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Component
public class CustomFilter2 extends AbstractGatewayFilterFactory<CustomFilter2.ConfigParam> {


    public CustomFilter2(){
        super(ConfigParam.class);
    }

    @Override
    public GatewayFilter apply(ConfigParam config) {
        return (exchange, chain) -> {
            if (config.isFlag()){
                System.out.println("piggy filter");
            }
            return chain.filter(exchange);
        };
    }

    @Override
    public List<String> shortcutFieldOrder() {
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("flag");
        arrayList.add("enable");
        return arrayList;
    }

    public static class ConfigParam{
        private boolean flag = false;

        private boolean enable = true;

        public boolean isEnable() {
            return enable;
        }

        public void setEnable(boolean enable) {
            this.enable = enable;
        }

        public boolean isFlag() {
            return flag;
        }

        public void setFlag(boolean flag) {
            this.flag = flag;
        }
    }
}
